package com.liwy3.order.controller;

import com.liwy3.api.RemoteAccountService;
import com.liwy3.api.RemoteProductService;
import com.liwy3.common.domain.R;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * Copyright © 元气森林（北京）食品科技集团有限公司. All rights reserved.
 *
 * @Description:
 * @author: Crazy4J
 * @date: 2022年02月24日 15:39
 * @version: V1.0
 *作者：沙皮喵
 * 链接：https://www.zhihu.com/question/277221676/answer/2255761142
 * 来源：知乎
 * 著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。
 *
 */
@RestController
public class OrderController {

    @Resource
    private RemoteAccountService remoteAccountService;
    @Resource
    private RemoteProductService remoteProductService;

    @PostMapping("/order/add")
    @GlobalTransactional
    public R<?> add(@RequestParam("orderNo") String orderNo) {
        remoteAccountService.add(new BigDecimal(100));
        remoteProductService.add(10);
        System.out.println("下单:" + orderNo + ",账户加:100,产品加10");
        return R.ok();
    }

}
